package com.xzx.spark.core.transform

import org.apache.spark.{SparkConf, SparkContext}

/**
 *
 * ${DESCRIPTION}
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2021-06-26 8:39 下午
 */
object Spark008_Distinct {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName("Spark008_Distinct")
    val context = new SparkContext(conf)
    val dataRDD = context.makeRDD(List(1, 2, 3, 4, 1, 2), 1)
    val dataRDD1 = dataRDD.distinct()
    dataRDD1.collect().foreach(println)
    println("===========================")
    val dataRDD2 = dataRDD.distinct(2)
    dataRDD2.collect().foreach(println)
    println("===========================")
    // 自己模拟distinct算子
    dataRDD.map(x => (x, null)).reduceByKey((x, y) => x).map(x => x._1).collect().foreach(println)

    context.stop()
  }
}
